#include <gtest/gtest.h>
#include "Spark/Utils/TimePoint.h"

TEST(TimePoint, diff_test)
{
    TimePoint now = TimePoint::Now();
    TimePoint then = now + 3_s;
    timespec diff = TimePoint::diffAsTimeSpec(now, then);
    EXPECT_EQ(diff.tv_sec, 3);
    EXPECT_GE(diff.tv_nsec, 0);
}

TEST(TimePoint, add_test)
{
    time_t t = time(nullptr);
    TimePoint tp(t);
    char buf[32]{};
    strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t));
    EXPECT_EQ(std::string(buf), tp.toString());
}

int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}